from dotenv import load_dotenv
import os
import pytest

from a3mall.Tools.tools import ApiClient

# 加载环境变量
load_dotenv()


@pytest.fixture(scope='function')
def client():
    """创建API客户端"""
    return ApiClient("http://10.59.9.12:7001/")


@pytest.fixture(scope='function')
def login_token(client):
    """获取登录token"""
    data = {
        'username': '19064013675',
        'password': '123456'
    }

    response = client.post(path="api/public/login", json_data=data)
    result = response.json()
    token = 'Bearer ' + result['data']['token']
    print(result)
    yield token
    return token
